﻿using System.ComponentModel;
using System.Dynamic;

namespace MelodysDemo.Application.AppServices
{
    public class DynamicPropertyDescriptor : PropertyDescriptor
    {
        private readonly Func<object, object> valueGetter;

        public DynamicPropertyDescriptor(string name, Func<object, object> valueGetter)
            : base(name, null)
        {
            this.valueGetter = valueGetter;
        }
        public override Type ComponentType => typeof(ExpandoObject);

        public override bool IsReadOnly => true;

        public override Type PropertyType => typeof(object);


        public override bool CanResetValue(object? component)
        {
            return false;
        }

        public override object GetValue(object component)
        {
            return valueGetter(component);
        }

        public override void ResetValue(object? component)
        {
            throw new NotImplementedException();
        }

        public override void SetValue(object? component, object? value)
        {
            throw new NotImplementedException();
        }

        public override bool ShouldSerializeValue(object? component)
        {
            return false;
        }

    }
}
